import * as Cesium from "cesium";

// 缩放方法 zoom.js
export function zoom(viewer,relativeAmount) {
    const { camera } = viewer;
    let focus = getCameraFocus(viewer, Cesium);
    let orientation = {
        direction: camera.direction,
        up: camera.up,
    };
    const cartesian3Scratch = new Cesium.Cartesian3();
    const direction = Cesium.Cartesian3.subtract(
        camera.position,
        focus,
        cartesian3Scratch
    );
    const movementVector = Cesium.Cartesian3.multiplyByScalar(
        direction,
        relativeAmount,
        direction
    );
    const endPosition = Cesium.Cartesian3.add(focus, movementVector, focus);
    camera.flyTo({
        destination: endPosition,
        orientation: orientation,
        duration: 0.5,
        convert: false,
    });
}
function getCameraFocus(scene) {
    const { defined, Ellipsoid, IntersectionTests, Ray } = Cesium;
    const ray = new Ray(scene.camera.positionWC, scene.camera.directionWC);
    const intersections = IntersectionTests.rayEllipsoid(ray, Ellipsoid.WGS84);
    if (defined(intersections)) {
        return Ray.getPoint(ray, intersections.start);
    }
    return IntersectionTests.grazingAltitudeLocation(ray, Ellipsoid.WGS84);
}
